package com.hongguowei.password;


//import org.apache.shiro.util.ByteSource;
import org.apache.shiro.crypto.hash.SimpleHash;
import org.apache.shiro.util.ByteSource;
//import org.springframework.util.DigestUtils;

public class Md5Salt {
    public static void main(String[] args) {
        String pwd1 = md5("123456", "admin8d78869f470951332959580424d4bf4f");
        System.out.println(pwd1);
        //密码：d3c59d25033dbf980d29554025c23a75
        String pwd2 = md5("123456", "abc0c23e95fd137ea96c4ef24366b7e6f1f");
        System.out.println(pwd2);
        //密码：ae8bb0dd40e4eddeac081f8e31afdaed
    }

    public static final String md5(String password, String salt){
        //加密方式
        String hashAlgorithmName = "MD5";
        //盐：相同密码使用不同的盐加密后的结果不同
        ByteSource byteSalt = ByteSource.Util.bytes(salt);
        //密码
        Object source = password;
        //加密次数
        int hashIterations = 2;
        SimpleHash result = new SimpleHash(hashAlgorithmName, source, byteSalt, hashIterations);
        return result.toString();

//        String s = DigestUtils.md5DigestAsHex("dd".getBytes());

    }
}
